using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;

namespace ITManagerProject {
  public class FeatureReceiver : SPFeatureReceiver {

    public override void FeatureActivated(SPFeatureReceiverProperties properties) {
      
        if (properties != null)
        {

            /* no op */

       
         
            //Khoi tao cac quyen co ban 


           
            //Moi doi tuong web tren SharePoint
            SPSite site = (SPSite)properties.Feature.Parent;
            SPWeb sweb = site.OpenWeb();

            //Thay doi giao dien khac
            SPFile defaultPage = sweb.Files["default.aspx"];//Tim Home Page
            defaultPage.Delete();// Xoa bo Home Page


            //Khoi tao home Page Moi

            SPFile newdefaultPage = sweb.Files["CustomeHomePage.aspx"];
            newdefaultPage.MoveTo("default.aspx", false);

            //Mo doi tuong list tren site
            SPListCollection collist = sweb.Lists;

            //khoi tao list tiepnhan
            collist.Add("TiepNhan", "List tiep Nhan", SPListTemplateType.GenericList);
            collist.Add("ThuLy", "List thu ly", SPListTemplateType.GenericList);
            

            //update lai doi tuong web
            sweb.Update();

            //Define all list 

            //Kiem tra su ton tai cua list
            if (Common.Checklistexits("TiepNhan", sweb))
            {

                //mo doi tuong tap hop truong trong list tiepnhan
                SPFieldCollection collField = collist["TiepNhan"].Fields;

                //Tao Column tren list tiep nhan
                collField.Add(Common.Constant.DEPARTMENTNAME, SPFieldType.Text, true);
                //collField.Add(Common.Constant.PROJECTNAME, SPFieldType.Text, true);
                collField.Add(Common.Constant.PROJECTNAME, SPFieldType.Text, false);
                //collField.Add(Common.Constant.RECEVINGBY, SPFieldType.User, true);
                collField.Add(Common.Constant.RECEVINGBY, SPFieldType.User, false);
                collField.Add(Common.Constant.RECEVINGDATE, SPFieldType.DateTime, false);
                //collField.Add(Common.Constant.REGESTRYNAME, SPFieldType.Text, true);
                collField.Add(Common.Constant.REGESTRYNAME, SPFieldType.Text, false);
                collField.Add(Common.Constant.STATUS, SPFieldType.Boolean, false);
                collField.Add(Common.Constant.NUMBERFILEATTACH, SPFieldType.Number, false);
                collField.Add(Common.Constant.IDCODE, SPFieldType.Text, false);
                collField.Add(Common.Constant.PROJECTVALUE, SPFieldType.Text, false);
                collField.Add(Common.Constant.PHONENUMBER, SPFieldType.Text, false);
                collField.Add(Common.Constant.FILENAME, SPFieldType.Text, false);
                collField.Add(Common.Constant.ADDTACHFILE, SPFieldType.Text, false);
                //update list tiep nhan
                collField.List.Update();
                collist["TiepNhan"].Update();


            }

            //Khoi tao list thu ly




            //khoi tao list ky duyet

        }

    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
        /* no op */
    }

    public override void FeatureInstalled(SPFeatureReceiverProperties properties) {
        /* no op */
    }
    public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {
        /* no op */
    }
  }
}
